package lium.lbs.lbsim.zfw

import lium.lbs.lbsim.R
import android.os.Bundle
import android.view.View
import android.widget.Toast
import com.buz.hjcdriver.bean.AResultBean
import com.lmlibrary.Constants
import com.lmlibrary.bean.ResponseBean
import com.lzy.okgo.model.Response
import kotlinx.android.synthetic.main.activity_set_remark.*
import lium.lbs.lbsim.activity.BaseActivity
import lium.lbs.lbsim.listener.ReMarketMessageEven
import lium.lbs.lbsim.utils.SpUtils
import lium.lbs.lbsim.utils.callbck.DialogCallback
import org.greenrobot.eventbus.EventBus

class SetRemarkActivity : BaseActivity() {

    var fid: String? = null

    override fun getLayoutId(): Int {
        return R.layout.activity_set_remark
    }

    override fun initView(savedInstanceState: Bundle?) {
        setTitleWithBack("设置备注")
        fid = intent.getStringExtra("fid")

        addOnClickListeners(R.id.contacts_save)
    }

    override fun getNetWorkData() {

    }

    fun getDataList() {
        val param = HashMap<String, String>()
        param["mid"] = SpUtils.getInstance().get(Constants.memberId, "") as String
        param["fid"] = fid.toString()//1：找人；2：找群
        param["remark"] = remark.text.toString()
        postData(
            "/frinds/updateRemark",
            param,
            object : DialogCallback<ResponseBean<AResultBean>>(this) {
                override fun onSuccess(response: Response<ResponseBean<AResultBean>>) {
                    setDataList(response.body().msg)
                    finish()
                    jumpActivity()
                }
            })
    }

    fun setDataList(msg: String) {
        Toast.makeText(this@SetRemarkActivity, msg, Toast.LENGTH_SHORT).show()
        finish()
    }


    override fun onClick(v: View?) {
        super.onClick(v)
        when (v!!.id) {
            R.id.contacts_save -> {
                if (remark.text == null) {
                    Toast.makeText(this@SetRemarkActivity, "备注名称不能为空", Toast.LENGTH_SHORT).show()
                } else {
                    getDataList()
                }
            }

        }
    }
    fun jumpActivity() {
        EventBus.getDefault().post(ReMarketMessageEven(1))
    }

}
